<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="活动标题" prop="activityName">
        <el-input
          v-model="queryParams.activityName"
          placeholder="请输入活动标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['activity:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['activity:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['activity:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['activity:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ActivityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="50" align="center" label="序号"></el-table-column>
      <el-table-column label="活动标题" align="center" prop="activityName" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span style="color: #1ab394" v-if="scope.row.status == 0">正常</span>
          <span style="color: red" v-else-if="scope.row.status == -1">下架</span>
          <span style="color: #3A71A8" v-else>其他</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="参与用户级别要求" align="center" prop="joinLevel">
        <template slot-scope="scope">
          <span v-if="scope.row.joinLevel == 0">最低级用户</span>
          <span v-else-if="scope.row.joinLevel == 1">低级用户</span>
          <span v-else-if="scope.row.joinLevel == 2">中级用户</span>
          <span v-else-if="scope.row.joinLevel ==3">高级用户</span>
          <span v-else-if="scope.row.joinLevel == 4">最高级用户</span>
          <span v-else>其他</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="参与用户类别要求" align="center" prop="joinType"> 
         <template slot-scope="scope">
          <span v-if="scope.row.joinType == 0">个人</span>
          <span v-else-if="scope.row.joinType == 1">私有企业</span>
          <span v-else-if="scope.row.joinType == 2">国有重点企业</span>
          <span v-else-if="scope.row.joinType == 3">组织机构</span>
          <span v-else-if="scope.row.joinType == 4">事业单位</span>
          <span v-else-if="scope.row.joinType == 5">普通局委办</span>
          <span v-else-if="scope.row.joinType == 6">权力机构</span>
          <span v-else>其他</span>
        </template>
      </el-table-column>      -->
      <el-table-column label="参与用户入网时间要求" align="center" prop="joinTime">
         <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动类别" align="center" prop="activityType" >
        <template slot-scope="scope">
          <span v-if="scope.row.activityType == 0">亲子活动</span>
          <span v-else-if="scope.row.activityType == 1">团体活动</span>
          <span v-else>其他</span>
        </template>
      </el-table-column>
      <el-table-column label="活动额度" align="center" prop="activityValue" />
      <el-table-column label="限购产品类别" align="center" prop="productType" >
        <template slot-scope="scope">
          <span v-if="scope.row.productType == 0">景区生产品</span>
          <span v-else-if="scope.row.productType == 1">手工雕刻产品</span>
          <span v-else>其他</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="限购数据用户类别" align="center" prop="limitType" >
        <template slot-scope="scope">
          <span v-if="scope.row.joinType == 0">个人</span>
          <span v-else-if="scope.row.joinType == 1">私有企业</span>
          <span v-else-if="scope.row.joinType == 2">国有重点企业</span>
          <span v-else-if="scope.row.joinType == 3">组织机构</span>
          <span v-else-if="scope.row.joinType == 4">事业单位</span>
          <span v-else-if="scope.row.joinType == 5">普通局委办</span>
          <span v-else-if="scope.row.joinType == 6">权力机构</span>
          <span v-else>其他</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="限购数据用户级别" align="center" prop="limitLevel" >
       <template slot-scope="scope">
          <span v-if="scope.row.joinLevel == 0">最低级用户</span>
          <span v-else-if="scope.row.joinLevel == 1">低级用户</span>
          <span v-else-if="scope.row.joinLevel == 2">中级用户</span>
          <span v-else-if="scope.row.joinLevel == 3">高级用户</span>
          <span v-else-if="scope.row.joinLevel == 4">最高级用户</span>
          <span v-else>其他</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="活动启动时间" align="center" prop="startTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>    
      </el-table-column>  
      <el-table-column label="活动结束时间" align="center" prop="endTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="参与人数限制" align="center" prop="limitNumber" />
      <el-table-column label="宣传URL" align="center" prop="activityUrl" />
      <el-table-column label="活动说明" align="center" prop="activityDescription" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleInfo(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['activity:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['activity:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改活动信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="活动标题" prop="activityName">
          <el-input v-model="form.activityName" placeholder="活动标题" />
        </el-form-item>
        <el-form-item label="参与用户级别要求" prop="joinLevel">
          <el-select v-model="form.joinLevel" placeholder="用户级别" >
            <el-option label="最低级用户" :value="0" />
            <el-option label="低级用户" :value="1" />
            <el-option label="中级用户" :value="2" />
            <el-option label="高级用户" :value="3" />
            <el-option label="最高级用户" :value="4" />
          </el-select>
        </el-form-item>
        <el-form-item label="参与用户类别要求" prop="joinType">
          <el-select v-model="form.joinType" placeholder="用户类别" >
            <el-option label="个人" :value="0"  />
            <el-option label="私人企业" :value="1" />
            <el-option label="国有重点企业" :value="2"  />
            <el-option label="组织机构" :value="3" />
            <el-option label="事业单位" :value="4"  />
            <el-option label="普通局委办" :value="5" />
            <el-option label="权力机构" :value="6"  />
          </el-select>
        </el-form-item>
        <el-form-item label="参与用户入网时间要求" prop="joinTime">
          <el-date-picker
            v-model="form.joinTime"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动类别" prop="activityType">
          <el-select v-model="form.activityType" placeholder="活动类别" >
            <el-option label="亲子活动" :value="0" />
            <el-option label="团体活动" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="活动额度" prop="activityValue">
          <el-input v-model.number="form.activityValue" placeholder="活动额度" />
        </el-form-item>
        <el-form-item label="限购产品类别" prop="productType">
          <el-select v-model="form.productType" placeholder="限购产品类型" >
            <el-option label="景区生产品" :value="0" />
            <el-option label="手工雕刻产品" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="限购数据用户类别" prop="limitType">
          <el-select v-model="form.limitType" placeholder="限购数据用户类别" >
            <el-option label="最低级用户" :value="0" />
            <el-option label="低级用户" :value="1" />
            <el-option label="中级用户" :value="2" />
            <el-option label="高级用户" :value="3" />
            <el-option label="最高级用户" :value="4" />
          </el-select>
        </el-form-item>
        <el-form-item label="限购数据用户级别" prop="limitLevel">
          <el-select v-model="form.limitLevel" placeholder="限购数据用户级别" >
            <el-option label="个人" :value="0"  />
            <el-option label="私人企业" :value="1" />
            <el-option label="国有重点企业" :value="2"  />
            <el-option label="组织机构" :value="3" />
            <el-option label="事业单位" :value="4"  />
            <el-option label="普通局委办" :value="5" />
            <el-option label="权力机构" :value="6"  />
          </el-select>       
        </el-form-item>
        <el-form-item label="活动启动时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动结束时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="参与人数限制" prop="limitNumber">
          <el-input v-model.number="form.limitNumber" placeholder="参与人数限制" />
        </el-form-item>
        <el-form-item label="宣传url" prop="activityUrl">
          <el-input v-model="form.activityUrl" placeholder="宣传url" />
        </el-form-item>
        <el-form-item label="活动说明" prop="activityDescription">
          <el-input v-model="form.activityDescription" placeholder="活动说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer"  prop="status">  
        <el-button type="primary" @click="submitForm" >确 定</el-button>
        <el-button type="success" @click="temporarily">暂 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看详情对话框 -->
    <el-dialog :title="title1" :visible.sync="See1" width="1300px" append-to-body>
      <el-form ref="form" :model="form" >
        <el-col :span="8">
          <el-form-item label="活动标题：">{{ form.activityName }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="参与人数限制：">{{ form.limitNumber }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="宣传url：">{{ form.activityUrl }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="活动说明：">{{ form.activityDescription }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="活动类别：">
            <div v-if="form.activityType === 0">亲子活动</div>
            <div v-else-if="form.activityType === 1">团体活动</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="活动额度：">{{ form.activityValue }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态：">
            <div v-if="form.status === 0">正常</div>
            <div v-else-if="form.status === -1">下架</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="参与用户级别要求：">
            <div v-if="form.joinLevel === 0">最低级用户</div>
            <div v-else-if="form.joinLevel === 1">低级用户</div>
            <div v-else-if="form.joinLevel === 2">中级用户</div>
            <div v-else-if="form.joinLevel === 3">高级用户</div>
            <div v-else-if="form.joinLevel === 4">最高级用户</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="参与用户类别要求：">
            <div v-if="form.joinType === 0">个人</div>
            <div v-else-if="form.joinType === 1">私人企业</div>
            <div v-else-if="form.joinType === 2">国有重点企业</div>
            <div v-else-if="form.joinType === 3">组织机构</div>
            <div v-else-if="form.joinType === 4">事业单位</div>
            <div v-else-if="form.joinType === 5">普通局委办</div>
            <div v-else-if="form.joinType === 6">权力机构</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="参与用户入网时间要求：">{{ parseTime(form.joinTime, '{y}-{m}-{d}') }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="限购产品类别：">
            <div v-if="form.activityType === 0">景区生产品</div>
            <div v-else-if="form.activityType === 1">手工雕刻产品</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="限购数据用户类别：">
            <div v-if="form.limitType === 0">最低级用户</div>
            <div v-else-if="form.limitType === 1">低级用户</div>
            <div v-else-if="form.limitType === 2">中级用户</div>
            <div v-else-if="form.limitType === 3">高级用户</div>
            <div v-else-if="form.limitType === 4">最高级用户</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="限购数据用户级别：">
            <div v-if="form.limitLevel === 0">个人</div>
            <div v-else-if="form.limitLevel === 1">私人企业</div>
            <div v-else-if="form.limitLevel === 2">国有重点企业</div>
            <div v-else-if="form.limitLevel === 3">组织机构</div>
            <div v-else-if="form.limitLevel === 4">事业单位</div>
            <div v-else-if="form.limitLevel === 5">普通局委办</div>
            <div v-else-if="form.limitLevel === 6">权力机构</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="活动启动时间：">{{ parseTime(form.startTime, '{y}-{m}-{d}') }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="活动结束时间：">{{ parseTime(form.endTime, '{y}-{m}-{d}') }}</el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" prop="status">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listActivity, getActivity, delActivity, addActivity, updateActivity } from "@/api/qysj/app/Activity.js";

export default {
  name: "Activity",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 引擎信息信息表格数据
      ActivityList: [],
      // 弹出层标题
      title: "",
      title1: "",
      // 是否显示弹出层
      open: false,
      See1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        activityName:null
        // auditId: null,
        // startTime: null,
        // endTime: null,
        // name: null,
        // createUserId: null,
        // type: null,
        // unit: null,
        // price: null,
        // status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询引擎信息信息列表 */
    getList() {
      this.loading = true;
      listActivity(this.queryParams).then(response => {
        this.ActivityList = response.rows;
        console.log(this.ActivityList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.See1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        auditId: null,
        startTime: null,
        endTime: null,
        name: null,
        createUserId: null,
        type: null,
        unit: null,
        price: null,
        remark: null,
        status: 0,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    handleQueryAll() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQueryAll();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加活动信息";
    },
    //暂存按钮
    temporarily() {
      this.$refs["form"].validate(valid => {
        this.form.status = -1;
        console.log(this.form.startTime);
        if (valid) {
          if (this.form.id != null) {
            updateActivity(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addActivity(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
        console.log("数据状态码为："+this.form.status);
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getActivity(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改活动信息";
      });
    },
    // 详情
    handleInfo(row){
      this.reset();
      const id = row.id || this.ids;
      getActivity(id).then((response) => {
        this.form = response.data;
        console.log(this.form);
        this.See1 = true;
        this.title1 = "活动信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.status = 0;
          if (this.form.id != null) {
            console.log(this.form.startTime)
            updateActivity(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            console.log(this.form.startTime)
            addActivity(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
        console.log("数据状态码为："+this.form.status);
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除活动标题为"' + row.activityName + '"的数据项？').then(function() {
        return delActivity(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('activity/export', {
        ...this.queryParams
      }, `Activity_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
